#include "Interpolation.h"
using namespace std;

class F1 : public Function
{
public:
    double operator ()(double x)
	{
	    double y;
	    y = 1/(1+pow(x,2));
	    return y;
	};
    
};

/** 
 * F2用来根据n的大小和题目所给的x函数生成对应的{x_i}向量
 * 
 * 
 * @return 
 */
class F2
{
private:
    int n;
public:
    vector<double> operator ()(int n)
	{
	    vector<double> X;
	    X.resize(n + 1);
	    for (int i = 0; i<=n; i++)
	    {
		X[i] = -5+10.0*i/n;
	    }
	    return X;
	};
};

int main(int argc, char* argv[])
{
    vector<double> N;
    vector<vector<double>> X, Y;
        
    F1 f;
    F2 getx;
    N = {2, 4, 6, 8};
    X.resize(N.size());
    Y.resize(N.size());
    for (int j = 0; j < N.size(); j++ )
    {
	X[j] = getx(N[j]);
	Y[j] = getvalues(X[j], f);
	Newton NI(X[j], Y[j]);
	
	cout << "n = " << N[j] << ", " << endl;

	cout << "X = " << "";
	for (int i = 0; i < X[j].size(); i++)
	{
	    cout << X[j][i] << " ";
	}
	cout << endl;
	
	cout << "Y = " << "";
	for (int i = 0; i < Y[j].size(); i++)
	{
	    cout << Y[j][i] << " ";
	}
	cout << endl;
	
	NI.printF();
    }
    for (int i = 0; i <= 50; i++)
    {
	cout << "-" << "";
    }
    cout << endl;
    return 0;
}
